package xyz.lwm.lazycat.event;

import lombok.Getter;
import xyz.lwm.lazycat.utility.DateUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.util.Date;

@Getter
public class AppFinishEvent implements Event {

    private final long timeMills;

    public AppFinishEvent() {
        this.timeMills = System.currentTimeMillis();
    }

    public Date getFinishTime() {
        return new Date(timeMills);
    }

    public String getFinishTimeStr() {
        return DateUtil.format(getFinishTime(), DateUtil.DEFAULT_PATTERN);
    }

    public Duration getDuration(long startTimeMillis) {
        return Duration.ofMillis(timeMills - startTimeMillis);
    }

    public String getDurationSec(long startTimeMillis) {
        Duration duration = getDuration(startTimeMillis);
        return new BigDecimal(duration.toMillis())
                .divide(new BigDecimal(1000), 3, RoundingMode.HALF_UP).toString();
    }

}
